package com.example.demo.controller;

import com.example.demo.domain.Doc;
import com.example.demo.req.DocQueryReq;
import com.example.demo.req.DocSaveReq;
import com.example.demo.resp.CommonResp;
import com.example.demo.resp.PageResp;
import com.example.demo.services.DocService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@RestController //这是返回接口
@RequestMapping("/doc")
public class DocController {

    @Resource
    private DocService docService;

    @GetMapping("/list")
    public CommonResp<PageResp<Doc>> list(@Valid DocQueryReq req){
        CommonResp<PageResp<Doc>> resp= new CommonResp<>();
        PageResp<Doc> list = docService.list(req);
        resp.setData(list);
        return  resp;
    }

    @GetMapping("/all")
    public CommonResp<List<Doc>> all(@Valid DocQueryReq req){
        CommonResp<List<Doc>> resp= new CommonResp<>();
        List<Doc> list = docService.all(req);
        resp.setData(list);
        return  resp;
    }

    @PostMapping("/save")
    public CommonResp<Doc> save(@Valid @RequestBody DocSaveReq req){
        CommonResp resp= new CommonResp<>();
        docService.save(req);
        return  resp;
    }

    @GetMapping("/delete")
    public CommonResp<Doc> delete(DocQueryReq req){
        CommonResp resp= new CommonResp<>();
        docService.delete(req);
        return  resp;
    }
}
